class Solution {
    public int cuttingRope(int n) {
        //每段都尽量分成3,那样最大
        int res = 1;

        if(n<4) {
            return n-1;
        }
        while(n>4) {
            res*=3;
            n-=3;
        }
        return res*=n;
    }
    public int cuttingRope1(int n) {
        int[] dp = new int[n+1];
        dp[2] = 1;
        for(int i = 3;i<n+1;i++) {
            for(int j = 2;j<i;j++) {
                dp[i] = Math.max(dp[i],Math.max(j*(i-j),j*dp[i-j]));
            }
        }
        return dp[n];
    }
}